class DB {
  constructor() {
    this.pool = require('mysql').createPool(require('./dbinit'))
  }
  query(sql, parmas) {
    return new Promise((resolve, reject) => {
      this.pool.getConnection((err, conn) => {
        if (err) {
          console.log('数据库连接失败');
          reject(err)
        };
        conn.query(sql, parmas, (err, result) => {
          if (err) {
            console.log('SQL语句执行失败');
            reject(err)
          };
          resolve(result);
          conn.release();
        })
      })
    })
  }
}
module.exports = new DB();